
import { uuid } from 'neurons-utils';
import { DataType, utils } from 'well-log-vis';
import { IDataSet, ITable } from 'well-log-vis/model/interfaces';































































function createColumnDraft(columnName: string, dataType: DataType, name: string, extras?: any) {
  const column = utils.createColumnDraft(columnName, dataType, name);
  if (extras) {
    Object.keys(extras).forEach(key => {
      column[key] = extras[key];
    })
  }
  return column;
}

export const testTable: ITable = {
    id: uuid(),
    name: '测试数据',
    columns: [
      createColumnDraft('code', DataType.STRING, '井号', { unit: '', field_name: 'code', device_type: '', device_mode: '' }),
      createColumnDraft('p1', DataType.DATE, '日期', { unit: '', field_name: 'TDATH', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p10', DataType.DOUBLE, '上米平均钻时', { unit: 'Min/m', field_name: 'ROP', device_type: 'zhljy', device_mode: 'sk2000' }),
      createColumnDraft('p10', DataType.DOUBLE, '上米平均钻时', { unit: 'Min/m', field_name: 'ROP', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p11', DataType.DOUBLE, '钻头进尺', { unit: 'm', field_name: 'FOOTAGE', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p12', DataType.DOUBLE, '转速', { unit: 'Rpm', field_name: 'RPM', device_type: 'szcl_lwd', device_mode: 'bench_tree' }),
      createColumnDraft('p12', DataType.DOUBLE, '大钩负荷', { unit: 'KN', field_name: 'HОOKLОAD', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p13', DataType.DOUBLE, '钻压', { unit: 'KN', field_name: 'WOB', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p14', DataType.DOUBLE, '转速', { unit: 'Rpm', field_name: 'RPM', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p14', DataType.DOUBLE, '测试', { unit: 'KN', field_name: 'N', device_type: 'zhljy', device_mode: 'sk2000' }),
      createColumnDraft('p15', DataType.DOUBLE, '扭矩', { unit: 'KN.m', field_name: 'TORQUE', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p17', DataType.DOUBLE, '立压', { unit: 'Mpa', field_name: 'STANDPRES', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p18', DataType.DOUBLE, '套管压力', { unit: 'MPa', field_name: 'CASPRES', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p19', DataType.DOUBLE, '泵冲1', { unit: 'SPM', field_name: 'SPM1', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p2', DataType.DATETIME, '时间', { unit: '', field_name: 'TTIME', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p20', DataType.DOUBLE, '泵冲2', { unit: 'SPM', field_name: 'SPM2', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p21', DataType.DOUBLE, '泵冲3', { unit: 'SPM', field_name: 'SPM3', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p22', DataType.DOUBLE, '入口流量', { unit: 'L/s', field_name: 'FLOWIN', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p23', DataType.DOUBLE, '出口流量', { unit: '%', field_name: 'FLOWOUT', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p24', DataType.DOUBLE, '入口密度', { unit: 'g/cm3', field_name: 'WEIGHTIN', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p25', DataType.DOUBLE, '出口密度', { unit: 'g/cm3', field_name: 'WEIGHTOUT', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p26', DataType.DOUBLE, '入口温度', { unit: 'deg_c', field_name: 'TEMPIN', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p27', DataType.DOUBLE, '出口温度', { unit: 'deg_c', field_name: 'TEMPOUT', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p28', DataType.DOUBLE, '入口电导', { unit: 'ms', field_name: 'CONDIN', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p29', DataType.DOUBLE, '出口电导', { unit: 'ms', field_name: 'CONDOUT', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p3', DataType.STRING, '数据类型标志', { unit: '', field_name: 'MARK', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p30', DataType.DOUBLE, '1号池体积', { unit: 'm3', field_name: 'PIT1', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p31', DataType.DOUBLE, '2号池体积', { unit: 'm3', field_name: 'PIT2', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p32', DataType.DOUBLE, '3号池体积', { unit: 'm3', field_name: 'PIT3', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p33', DataType.DOUBLE, '4号池体积', { unit: 'm3', field_name: 'PIT4', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p34', DataType.DOUBLE, '5号池体积', { unit: 'm3', field_name: 'PIT5', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p35', DataType.DOUBLE, '6号池体积', { unit: 'm3', field_name: 'PIT6', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p37', DataType.DOUBLE, '总体积', { unit: 'm3', field_name: 'TOTALPIT', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p39', DataType.DOUBLE, '总烃', { unit: '%', field_name: 'TG', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p4', DataType.STRING, '综合仪发过来的井号', { unit: '', field_name: 'ZHYJH', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p40', DataType.DOUBLE, 'C1', { unit: '%', field_name: 'C1', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p41', DataType.DOUBLE, 'C2', { unit: '%', field_name: 'C2', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p42', DataType.DOUBLE, 'C3', { unit: '%', field_name: 'C3', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p43', DataType.DOUBLE, 'iC4', { unit: '%', field_name: 'IC4', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p44', DataType.DOUBLE, 'nC4', { unit: '%', field_name: 'NC4', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p45', DataType.DOUBLE, 'iC5', { unit: '%', field_name: 'IC5', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p46', DataType.DOUBLE, 'nC5', { unit: '%', field_name: 'NC5', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p47', DataType.DOUBLE, 'H2', { unit: '%', field_name: 'H2', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p48', DataType.DOUBLE, 'CO2', { unit: '%', field_name: 'C02', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p5', DataType.DOUBLE, '3号池体积', { unit: 'm', field_name: 'DEPTH', device_type: 'syyq', device_mode: 'ses' }),
      createColumnDraft('p5', DataType.DOUBLE, '实测井深', { unit: 'm', field_name: 'DEPTH', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p50', DataType.DOUBLE, 'DC指数', { unit: '', field_name: 'DC', device_type: 'zhljy', device_mode: 'ALS_23' }),
      // createColumnDraft('p50', DataType.DOUBLE, 'DC指数', { unit: '', field_name: 'DC', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p52', DataType.DOUBLE, '循环当量密度', { unit: 'g/cm3', field_name: 'TRIPTANK', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p53', DataType.DOUBLE, '钻头时间', { unit: 's', field_name: 'H2S_6', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p6', DataType.DOUBLE, '迟到井深', { unit: 'm', field_name: 'LAGDEPTH', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p7', DataType.DOUBLE, '大钩高度', { unit: 'm', field_name: 'BKHT', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p72', DataType.STRING, '钻井状态', { unit: '', field_name: 'RIGSTA', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p73', DataType.DOUBLE, '7号池体积', { unit: 'm3', field_name: 'PIT7', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p74', DataType.DOUBLE, '8号池体积', { unit: 'm3', field_name: 'PIT8', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p75', DataType.DOUBLE, '9号池体积', { unit: 'm3', field_name: 'PIT9', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p76', DataType.DOUBLE, '10号池体积', { unit: 'm3', field_name: 'PIT10', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p79', DataType.DOUBLE, '垂直井深', { unit: 'm', field_name: 'VDEPTH', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p9', DataType.DOUBLE, '钻井液迟到时间', { unit: 'Min', field_name: 'LAGTIME', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('p97', DataType.DOUBLE, '钻头位置', { unit: 'm', field_name: 'BITDEPTH', device_type: 'zhljy', device_mode: 'ALS_23' }),
      createColumnDraft('createTime', DataType.DOUBLE, '创建时间', { unit: 'ms', field_name: 'createTime', device_type: '', device_mode: '' }),
    ]
}

function randomNumber(): number {
    return 1000 + Math.random() * 10000;
}
function randomInt(): number {
    return Math.floor(1000 + Math.random() * 10000);
}
function randomBoolean(): boolean {
    return Math.random() >= 0.5;
}

const dayTime = 24 * 60 * 60 * 1000;

function randomDate(): number {
    const current = (new Date()).getTime();
    return Math.floor(current - (Math.random() * 30) * dayTime);
}
const toDay = new Date();
toDay.setMilliseconds(0);
let fromTime = toDay.getTime() - dayTime;
fromTime = 2000 * Math.floor(fromTime / 2000);
function plusDate(): Date {
    fromTime += 2000;
    return new Date(fromTime);
}
let fromDepth = 0;
function plusDepth(): number {
    fromDepth += Math.random() * 100;
    return fromDepth;
}

function randomString(prefix, count): string {
    return prefix + '_' + count;
}

const values: any[] = [];

for (let i = 0; i < 2000; i++) {
    const row = testTable.columns.map(col => {
        if (col.columnName === 'depth_field') return plusDepth();
        if (col.columnName === 'p2') return plusDate();
        switch (col.dataType) {
            case DataType.DATE:
            case DataType.DATETIME:
                return randomDate();
            case DataType.INTEGER:
                return randomInt();
            case DataType.DOUBLE:
                return randomNumber();
            default:
                return randomString(col.name || 'dim', i);
        }
    })
    values.push(row);
}

export const testDataSet: IDataSet = {
    columns: testTable.columns,
    values: values
}
